{% extends 'dashboard/layout.html' %}
{% load i18n %}

{% block body_class %}{{ block.super }} create-page promotions{% endblock %}

{% block breadcrumbs %}
    <ul class="breadcrumb">
        <li>
            <a href="{% url 'dashboard:index' %}">{% trans "Dashboard" %}</a>
        </li>
        <li>
            <a href="{% url 'dashboard:promotion-list' %}">{% trans "Content blocks" %}</a>
        </li>
        <li class="active">{{ heading }}</li>
    </ul>
{% endblock %}

{% block headertext %}
    {{ heading }}
{% endblock %}

{% block dashboard_content %}

    {% block promotion_form %}
        <div class="table-header">
            <h2>{% trans "Content block" %}</h2>
        </div>

        <form method="post" enctype="multipart/form-data" class="well form-stacked wysiwyg">
            {% csrf_token %}
            {% include "dashboard/partials/form_fields.html" with form=form %}

            {% block inlines %} {% endblock %}

            <div class="form-actions">
                <button type="submit" class="btn btn-primary" data-loading-text="{% trans 'Saving...' %}">{% trans "Save" %}</button>
                {% trans "or" %} <a href="{% url 'dashboard:promotion-list' %}">{% trans "cancel" %}</a>
            </div>
        </form>

    {% endblock %}

    {% if promotion %}
        <table class="table table-striped table-bordered table-hover">
            <caption>{% trans "Pages displaying this content blocks" %}</caption>
            {% if links %}
                <thead>
                    <tr>
                        <th>{% trans "Page URL" %}</th>
                        <th>{% trans "Position on page" %}</th>
                        <th>{% trans "Actions" %}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for link in links %}
                        <tr>
                            <td><a href="{{ link.page_url }}">{{ link.page_url }}</a></td>
                            <td>{{ link.position }}</td>
                            <td>
                                <form method="post" >
                                    {% csrf_token %}
                                    <input type="hidden" name="action" value="remove_from_page" />
                                    <input type="hidden" name="pagepromotion_id" value="{{ link.id }}" />
                                    <a href="{% url 'dashboard:promotion-list-by-url' path=link.page_url %}" class="btn btn-info">{% trans "View all blocks on this page" %}</a>
                                    <button class="btn btn-default" type="submit" data-loading-text="{% trans 'Removing...' %}">{% trans "Remove from page" %}</button>
                                </form>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            {% else %}
                <tr><td>{% trans "This promotion is not displayed anywhere at the moment." %}</td></tr>
            {% endif %}
        </table>
        <div class="table-header">
            <h3>{% trans "Add to a page" %}</h3>
        </div>
        <div class="well">
            <form method="post" class="form-stacked">
                {% csrf_token %}
                <input type="hidden" name="action" value="add_to_page" />
                {% include "dashboard/partials/form_fields.html" with form=link_form %}
                <button type="submit" class="btn btn-success" data-loading-text="{% trans 'Adding...' %}">{% trans "Add to page" %}</button>
            </form>
        </div>
    {% endif %}

{% endblock %}
